//
//  THCardView.swift
//  LaiLang
//
//  Created by David on 2017/2/21.
//  Copyright © 2017年 David. All rights reserved.
//

import UIKit

class THCardView: UIView {

    var bgColor: UIColor?{
        get{
            return contentBG.backgroundColor
        }
        set(ds){
            contentBG.backgroundColor = ds
        }
    }
    
    var contentBG: UIView!
    
    var fullContent: NSAttributedString{
        get{
            return contentLabel.attributedText
        }
        set(f){
            contentLabel.attributedText = f
        }
    }
    
    var contentLabel: UITextView!
    var rightLabel: UILabel!
    
    var bottomContent: String?{
        get{
            return rightLabel.text
        }
        set(t){
            rightLabel.text = t
        }
    }
    
    var toMajorTag: LLRoundRectLabel!
    
    var toMajor: String?{
        get{
            return toMajorTag.text
        }
        set(t){
            toMajorTag.text = t
        }
    }
    
    var likeBtn: UIButton!
    var commentBtn: UIButton!
    
    var _likeNum: Int = 0
    var likeNum: Int{
        get{
            return _likeNum
        }
        set(d){
            _likeNum = d
            let showStr = "\u{e6a4} \(likeNum)"
            let attrStr = NSMutableAttributedString(string: showStr)
            attrStr.addAttribute(NSForegroundColorAttributeName, value: UIColor.lightGray, range: NSMakeRange(0, showStr.characters.count))
            attrStr.addAttribute(NSFontAttributeName, value: UIFont(name: "iconfont", size: 16)!, range: NSMakeRange(0, 1))
            attrStr.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 14), range: NSMakeRange(1, showStr.characters.count - 1))
            likeBtn.setAttributedTitle(attrStr, for: .normal)
        }
    }
    
    var _commentNum: Int = 0
    var commentNum: Int{
        get{
            return _commentNum
        }
        set(d){
            _commentNum = d
            let showStr = "\u{e621} \(commentNum)"
            
            let attrStr = NSMutableAttributedString(string: showStr)
            attrStr.addAttribute(NSForegroundColorAttributeName, value: UIColor.lightGray, range: NSMakeRange(0, showStr.characters.count))
            attrStr.addAttribute(NSFontAttributeName, value: UIFont(name: "iconfont", size: 16)!, range: NSMakeRange(0, 1))
            attrStr.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 14), range: NSMakeRange(1, showStr.characters.count - 1))
            commentBtn.setAttributedTitle(attrStr, for: .normal)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.white
        layer.cornerRadius = 8
        layer.masksToBounds = true
        
        contentBG = UIView(frame: CGRect(x: 0, y: 0, width: bounds.width, height: 168))
        addSubview(contentBG)
        
        contentLabel = UITextView(frame: CGRect(x: 16, y: 4, width: bounds.width - 32, height: 120))
        //                contentLabel.numberOfLines = 0
        contentLabel.isEditable = false
        contentLabel.isSelectable = false
        contentLabel.isScrollEnabled = false
        contentLabel.backgroundColor = UIColor.clear
        contentLabel.textColor = UIColor.white
        contentBG.addSubview(contentLabel)
        
        
        rightLabel = UILabel(frame: CGRect(x: 16, y: 128, width: bounds.width - 32, height: 36))
        rightLabel.textColor = UIColor.white
        rightLabel.numberOfLines = 0
        rightLabel.textAlignment = .right
        rightLabel.font = UIFont.systemFont(ofSize: 14)
        contentBG.addSubview(rightLabel)
        
        
        toMajorTag = LLRoundRectLabel(frame: CGRect(x: 0, y: 28, width: 200, height: 16))
        //                toMajorTag.layer.borderColor = themeColor.cgColor
        //                toMajorTag.layer.borderWidth = 1
        //                toMajorTag.layer.cornerRadius = 4
        toMajorTag.textColor = UIColor.white
        toMajorTag.font = UIFont.systemFont(ofSize: 10)
        //                toMajorTag.textAlignment = .center
        contentLabel.addSubview(toMajorTag)
        
        likeBtn = UIButton(frame: CGRect(x: 16, y: 176, width: 48, height: 20))
        
        addSubview(likeBtn)
        
        commentBtn = UIButton(frame: CGRect(x: 80, y: 176, width: 48, height: 20))
        
        addSubview(commentBtn)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
